<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>学生管理</title>
    <link type="text/css" rel="stylesheet" href="/static/css/bootstrap.css">
    <link type="text/css" rel="stylesheet" href="/static/bootstrapValidator/bootstrapValidator.css">
</head>
<body>

<div class="container">
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <h1>学生管理系统</h1>
            </div>
        </div>
    </nav>


    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>学生信息
                    <small>检录</small>
                </h2>
                <div class="clearfix"></div>
            </div>

            <div class="x_content">
                <br>
                <div th:if="${msg}">
                    <div class="alert alert-info alertDia">
                        <a href="#" class="close" data-dismiss="alert">
                            &times;
                        </a>
                        <strong>提示: <span th:text="${msg}"></span></strong>
                    </div>
                </div>

                <div th:if="${#httpServletRequest.getParameter('msg')}">
                    <div class="alert alert-info alertDia">
                        <a href="#" class="close" data-dismiss="alert">
                            &times;
                        </a>
                        <strong>提示: <span th:text="${#httpServletRequest.getParameter('msg')}"></span></strong>
                    </div>
                </div>
                <form id="demo-form2" data-parsley-validate="" class="form-horizontal form-label-left" novalidate=""
                      action="/addStu" th:method="POST">

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="stuNum">学生编号<span
                                class="required">*</span>
                        </label>
                        <input hidden="hidden" type="text" id="id" name="id" th:value="${stu.id}">

                        <div class="col-md-3 col-sm-3 col-xs-12">
                            <input type="text" id="stuNum" name="stuNum" th:value="${stu.stuNum}"
                                   class="form-control col-md-7 col-xs-12">
                        </div>

                        <div class="col-md-3 col-sm-3 col-xs-12">
                            <span class="btn btn-info" id="stuNumSearch">搜索</span>
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="stuName">学生姓名 <span
                                class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="stuName" name="stuName" th:value="${stu.stuName}"
                                   class="form-control col-md-7 col-xs-12">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">身份证号码 <span
                                class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input id="idCard" class="form-control col-md-7 col-xs-12" type="text"
                                   th:value="${stu.idCard}"
                                   name="idCard">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">专业<span
                                class="required">*</span></label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input id="stuMajor" class="date-picker form-control col-md-7 col-xs-12" name="stuMajor"
                                   th:value="${stu.stuMajor}"
                                   type="text">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">家长联系方式</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input id="stuParentContact" class="form-control col-md-7 col-xs-12" type="text"
                                   th:value="${stu.stuParentContact}"
                                   name="stuParentContact">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">学生联系方式</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input class="form-control col-md-7 col-xs-12" type="text" id="stuContact"
                                   th:value="${stu.stuContact}"
                                   name="stuContact">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">发票编号</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input class="form-control col-md-7 col-xs-12" type="text" name="invoceNumber"
                                   th:value="${stu.invoceNumber}">
                        </div>
                    </div>

                    <div class="ln_solid"></div>
                    <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                            <button type="submit" class="btn btn-success" id="btn-test">提交</button>
                            <button class="btn btn-primary" type="reset">重置</button>

                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>


</div>

</body>
<script type="text/javascript" src="/static/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap.js"></script>
<script type="text/javascript" src="/static/bootstrapValidator/bootstrapValidator.js"></script>
<script type="text/javascript">
    $(function () {
        $("#demo-form2").bootstrapValidator({
            live: 'disabled',//验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
            excluded: [':disabled', ':hidden', ':not(:visible)'],//排除无需验证的控件，比如被禁用的或者被隐藏的
            submitButtons: '#btn-test',//指定提交按钮，如果验证失败则变成disabled，但我没试成功，反而加了这句话非submit按钮也会提交到action指定页面
            message: '通用的验证失败消息',//好像从来没出现过
            feedbackIcons: {//根据验证结果显示的各种图标
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                stuNum: {
                    message: '学生编号不能为空',
                    validators: {
                        notEmpty: {
                            message: '学生编号不能为空'
                        }
                    }
                },
                stuName: {
                    validators: {
                        notEmpty: {
                            message: '学生名字不能为空'
                        }
                    }
                },
                idCard: {
                    validators: {
                        notEmpty: {
                            message: '身份证信息不能为空'
                        },
                        regexp: {
                            regexp: /(^\d{15}$)|(^\d{17}(\d|X)$)/,
                            message: '身份证只能15到18位'
                        }
                    }
                },
                stuMajor: {
                    validators: {
                        notEmpty: {
                            message: '专业信息不能为空'
                        }
                    }
                },
                stuParentContact: {
                    validators: {
                        regexp: {
                            regexp: /^[1][3,4,5,7,8][0-9]{9}$/,
                            message: '请填写正确手机号'
                        }
                    }
                },
                stuContact: {
                    validators: {
                        regexp: {
                            regexp: /^[1][3,4,5,7,8][0-9]{9}$/,
                            message: '请填写正确手机号'
                        }
                    }
                }
            }
        });

        $('#stuNumSearch').click(function () {
            var stuNum = $('#stuNum').val();
            if (stuNum === null) {
                return
            }
            window.location.href = '/search?stuNum=' + stuNum
        })


        setTimeout(function () {
            $('.alertDia').alert('close');
        }, 4000)

    })

</script>
</html>